package com.sdp.khy.baotou.controller;


import com.sdp.core.bizc.db.Query;
import com.sdp.core.bizc.vo.DataCenter;
import com.sdp.core.bizc.vo.Result;
import com.sdp.khy.baotou.db.khy_service_qa.entity.KhyServiceQa;
import com.sdp.khy.baotou.db.khy_service_qa.service.IKhyServiceQaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zsp
 * @since 2023-12-03
 */
@RestController
@RequestMapping("/KhyServiceQaController")
public class KhyServiceQaController {


	@Autowired
	private IKhyServiceQaService serviceQaService;



	@Autowired
	private Query query;

	@PostMapping(value = "/page")
	public Result<?> page(@RequestBody DataCenter dataCenter) {
		return Result.ok(query.page(serviceQaService, KhyServiceQa.class, dataCenter));
	}

	@PostMapping(value = "/save")
	@Transactional(rollbackFor=Exception.class)
	public Result<?> save(@RequestBody KhyServiceQa khyServiceQa) {
		if(khyServiceQa==null) {
			return Result.error("信息为空");
		}
		if(StringUtils.isEmpty(khyServiceQa.getKeyId())) {
			khyServiceQa.setCreateTime(LocalDateTime.now());
			serviceQaService.save(khyServiceQa);
		}else {
			serviceQaService.updateById(khyServiceQa);
		}
		return Result.ok();
	}

	@GetMapping(value = "/del")
	@Transactional(rollbackFor=Exception.class)
	public Result<?> del(@RequestParam(name="keyId",required=true) String keyId) {
		if(StringUtils.isEmpty(keyId)) {
			return Result.error("删除的客服信息不完整");
		}
		serviceQaService.removeById(keyId);

		return Result.ok();
	}
}

